package com.xiaoxing.salesclient.mvp.ui.popup;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xiaoxing.salesclient.mvp.ui.inter.ZhuangJie;

import me.jessyan.armscomponent.commonres.view.popup.BasePopupWindow;
import me.jessyan.armscomponent.commonres.view.popup.OverShootInterpolator;
import xiaoxing.com.salesclient.R;


/**
 * 全屏的popup
 */

public class ZhuanJiePopup extends BasePopupWindow implements View.OnClickListener {
    private View popupView;
    private Activity mActivity;

    private TextView tv_que_ren;
    private ZhuangJie mZhuangJie;
    private String mStaffId;
    private String mOrderId;
    private String mCover;
    private String mNickname;


    public ZhuanJiePopup(Activity context, ZhuangJie zhuangJie, String order_id, String staff_id, String cover, String nick_name) {
        super(context);
        this.mActivity = context;
        this.mZhuangJie = zhuangJie;
        this.mOrderId = order_id;
        this.mStaffId = staff_id;
        this.mCover = cover;
        this.mNickname = nick_name;

        /**全屏popup*/
        setPopupWindowFullScreen(true);
        bindEvent();
    }

    @Override
    protected Animation initShowAnimation() {
        return null;
    }

    @Override
    public Animator initShowAnimator() {
        AnimatorSet set;
        set = new AnimatorSet();
        ObjectAnimator transAnimator = ObjectAnimator.ofFloat(mAnimaView, "translationY", 250, 0).setDuration(600);
        transAnimator.setInterpolator(new OverShootInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mAnimaView, "alpha", 0.4f, 1).setDuration(250 * 3 / 2);
        set.playTogether(transAnimator, alphaAnimator);
        return set;
    }

    @Override
    public Animator initExitAnimator() {
        AnimatorSet set;
        set = new AnimatorSet();
        ObjectAnimator transAnimator = ObjectAnimator.ofFloat(mAnimaView, "translationY", 0, 250).setDuration(600);
        transAnimator.setInterpolator(new OverShootInterpolator(-6));
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mAnimaView, "alpha", 1f, 0).setDuration(800);
        set.playTogether(transAnimator, alphaAnimator);
        return set;
    }

    @Override
    public View getClickToDismissView() {
        return getPopupWindowView();
    }

    @Override
    public View onCreatePopupView() {
        popupView = createPopupById(R.layout.popup_zhuan_jie);
        return popupView;
    }

    @Override
    public View initAnimaView() {
        return findViewById(R.id.popup_anima);
    }

    private void bindEvent() {
        if (popupView != null) {

            popupView.findViewById(R.id.img_close).setOnClickListener(this);
            popupView.findViewById(R.id.tv_que_ren).setOnClickListener(this);

            TextView tv_name = popupView.findViewById(R.id.tv_name);
            if (!TextUtils.isEmpty(mNickname))
                tv_name.setText(mNickname);
//            ImageView img_head = popupView.findViewById(R.id.img_head);
//
//            Glide.with(mActivity).load(mCover).into(img_head);

        }
    }


    @Override
    public void onClick(View v) {
        int i = v.getId();

        if (i == R.id.img_close) {
            dismiss();
        } else if (i == R.id.tv_que_ren) {
            dismiss();
            mZhuangJie.zhuanJie(mOrderId, mStaffId);
        }

    }
}
